extends Node2D

var Player = preload("res://actor/player.tscn")
var MapTexture = preload("res://map/MapTexture.tscn")
var Enemy = preload("res://enemy/enemy.tscn")
var mapTexture
var players = []
var enemys = []
var turns = 1
var curTurn = true

func init(level):
	var levelConfig = LevelConfig.getLevelConfig(level)
	## 初始化地图
	mapTexture.initMap(levelConfig.get("map"))
	
	## 初始化角色
	for playerConfig in levelConfig.get("actors"):
		var player = Player.instance()
		add_child(player)
		player.initPlayer(levelConfig.get("actors")[0], mapTexture.mapTypes)
		players.append(player)

	## 初始化怪物
	print(levelConfig.get("enemys").size())
	for enemyConifg in levelConfig.get("enemys"):
		var enemy = Enemy.instance()
		add_child(enemy)
		enemy.initEnemy(enemyConifg, mapTexture.mapTypes)
		enemys.append(enemy)

## 执行步数结束
func stepOver():
	## 判断是否达成公关条件
	## 判断是否回合结束
	curTurn =  yield(TurnCheck.checkTurnOver(self), "completed")
	## 敌方回合
	if !curTurn:
		EnemyTurn.enemyStart(self)
	pass

func _ready():
	mapTexture = MapTexture.instance()
	add_child(mapTexture)

	init(1)
